package com.family.service.impl;

import com.family.mapper.WechatMapper;
import com.family.model.WechatInfo;
import com.family.service.WechatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service("wechatService")
public class WechatServiceImpl implements WechatService {
    private WechatMapper wechatMapper;

    @SuppressWarnings("SpringJavaAutowiringInspection")
    @Autowired
    public void setWechatMapper(WechatMapper wechatMapper) {
        this.wechatMapper = wechatMapper;
    }

    @Override
    public WechatInfo queryWechatByToken(String wechatToken) {
        return wechatMapper.queryWechatByToken(wechatToken);
    }

    @Override
    public int addOrUpdateWechatInfo(WechatInfo info) {
        if (info == null) {
            return -1;
        } else if (info.getId() > 0) {
            wechatMapper.updateWechatInfo(info);
            return info.getId();
        } else {
            return wechatMapper.addWechatInfo(info);
        }
    }
}
